-- _____ ______   ________  ________   ___  _________  ________  ________          ________  ___  ________  ___  __
--|\   _ \  _   \|\   __  \|\   ___  \|\  \|\___   ___\\   __  \|\   __  \        |\   ___ \|\  \|\   ____\|\  \|\  \
--\ \  \\\__\ \  \ \  \|\  \ \  \\ \  \ \  \|___ \  \_\ \  \|\  \ \  \|\  \       \ \  \_|\ \ \  \ \  \___|\ \  \/  /|_
-- \ \  \\|__| \  \ \  \\\  \ \  \\ \  \ \  \   \ \  \ \ \  \\\  \ \   _  _\       \ \  \ \\ \ \  \ \_____  \ \   ___  \
--  \ \  \    \ \  \ \  \\\  \ \  \\ \  \ \  \   \ \  \ \ \  \\\  \ \  \\  \|       \ \  \_\\ \ \  \|____|\  \ \  \\ \  \
--   \ \__\    \ \__\ \_______\ \__\\ \__\ \__\   \ \__\ \ \_______\ \__\\ _\        \ \_______\ \__\____\_\  \ \__\\ \__\
--    \|__|     \|__|\|_______|\|__| \|__|\|__|    \|__|  \|_______|\|__|\|__|        \|_______|\|__|\_________\|__| \|__|
--                                                                                                  \|_________|
-- banner online tools
-- https://www.bootschool.net/ascii;bsid=FB5C2059677902AEBA0B2640589E9FE8

local require  = require;
local ngx      = ngx;
local debug    = debug;
local string   = string;
local tonumber = tonumber;
local setmetatable = setmetatable
local pairs    = pairs
local type     = type
local table    = table

local table_concat     = table.concat

local math       = math
local math_floor = math.floor

local uu         = require("modules.commhm.utils");
local log        = require("modules.commhm.log");

--- 特性:
--- 1.各个磁盘使用率监控

local _M = { _VERSION = '0.43.1' }




---获取各个磁盘使用率
---@return boolean,table	指令是否成功调用,{各个磁盘使用率(0-1之间)}
function _M.getUsage()
	local ret_string_ = uu.os_exec( "df -lm  | grep -v 'tmpfs' | grep -v wangguoqing | awk '{print $5}'" )
	if ret_string_ == nil or ret_string_ == "" then
		return false, {}
	end
	local list_ = uu.split(ret_string_, '%')
	local ret_list_ = {}
	for i = 2, #list_ do
		local v = list_[i]
		local n = tonumber(v)
		if n then
			log.debug(i.."="..n)
			ret_list_[#ret_list_+1] = n/100.0
		end
	end
	return true, ret_list_
end


---获取所有磁盘中,使用率最高的使用率
---@return boolean,number	指令是否成功调用,最高的磁盘使用率(0-1之间)
function _M.getMaxUsage()
	local success, list_ = _M.getUsage()
	if not success then
		return false
	end
	local max = 0
	for k, v in pairs(list_) do
		if v > max then
			max = v
		end
	end
	return true, max
end


return _M;
